package com.example.auth.common.base;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * <p>
 *
 * </p>
 *
 * @author Ashe
 * @version V1.0
 * @date 2018年12月27日 17:26
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人} 2018年12月27日
 * @modify reason: {方法名}:{原因}
 * ...
 */
@Data
@Accessors(chain = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ResponseJson<T> {

    private String msg;
    private String code;
    private T data;

    public ResponseJson<T> failed(IErrorCode errorCode) {
        this.code = errorCode.getCode();
        this.msg = errorCode.getMsg();
        return this;
    }

    public ResponseJson<T> failed(String errorMsg) {
        this.code = "-1";
        this.msg = errorMsg;
        return this;
    }

    public ResponseJson<T> ok(T data) {
        this.data = data;
        this.code = "0";
        this.msg = "success";
        return this;
    }

    public ResponseJson<T> failed(T data, IErrorCode errorCode) {
        this.data = data;
        this.code = errorCode.getCode();
        this.msg = errorCode.getMsg();
        return this;
    }
}
